﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace B.S.DataBase.Production.Infrastructure.Migrations
{
    public partial class cv : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "materialListModels",
                columns: table => new
                {
                    MaterialListId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Code = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Remark = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Specification = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Unit = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Quantity = table.Column<double>(type: "float", nullable: false),
                    ProductRole = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProcessFlow = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    DefectRate = table.Column<double>(type: "float", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_materialListModels", x => x.MaterialListId);
                });

            migrationBuilder.CreateTable(
                name: "ProductionModels",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    DocumentSubject = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    DocumentNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MaterialDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    SourceDocumentType = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    SourceDocument = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    DocumentDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DocumentCreator = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    RelatedProject = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Remarks = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProductionModels", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SubComponentModel",
                columns: table => new
                {
                    SubComponentId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Index = table.Column<int>(type: "int", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Specification = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Unit = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Ratio = table.Column<double>(type: "float", nullable: false),
                    RequiredQuantity = table.Column<double>(type: "float", nullable: false),
                    ProductRole = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProcessFlow = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    DefectRate = table.Column<double>(type: "float", nullable: false),
                    PickMethod = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Remark = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MaterialListModelMaterialListId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SubComponentModel", x => x.SubComponentId);
                    table.ForeignKey(
                        name: "FK_SubComponentModel_materialListModels_MaterialListModelMaterialListId",
                        column: x => x.MaterialListModelMaterialListId,
                        principalTable: "materialListModels",
                        principalColumn: "MaterialListId");
                });

            migrationBuilder.CreateTable(
                name: "MaterialDetails",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Sequence = table.Column<int>(type: "int", nullable: false),
                    ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Model = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Unit = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MaterialQuantity = table.Column<int>(type: "int", nullable: false),
                    WarehouseManager = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ExistingInventory = table.Column<int>(type: "int", nullable: false),
                    DeliveryDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Remarks = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    MaterialMethod = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    RelatedDocument = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ProductionModelId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialDetails", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MaterialDetails_ProductionModels_ProductionModelId",
                        column: x => x.ProductionModelId,
                        principalTable: "ProductionModels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MaterialDetails_ProductionModelId",
                table: "MaterialDetails",
                column: "ProductionModelId");

            migrationBuilder.CreateIndex(
                name: "IX_SubComponentModel_MaterialListModelMaterialListId",
                table: "SubComponentModel",
                column: "MaterialListModelMaterialListId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MaterialDetails");

            migrationBuilder.DropTable(
                name: "SubComponentModel");

            migrationBuilder.DropTable(
                name: "ProductionModels");

            migrationBuilder.DropTable(
                name: "materialListModels");
        }
    }
}
